CC=g++
CFLAGS=-c -Wall -g
LDFLAGS=

MAIN_SOURCE := $(wildcard src/*.cpp)
MAIN_OBJECTS := $(addprefix obj/,$(notdir $(MAIN_SOURCE:.cpp=.o)))
FS_SOURCES := $(wildcard src/fs/*.cpp)
FS_OBJECTS := $(addprefix obj/fs/,$(notdir $(FS_SOURCES:.cpp=.o)))
SHELL_SOURCES := $(wildcard src/shell/*.cpp)
SHELL_OBJECTS := $(addprefix obj/shell/,$(notdir $(SHELL_SOURCES:.cpp=.o)))

EXECUTABLE=cs560fs #test_filesystem #test_directories shell

all: $(EXECUTABLE)

#link .o's to binary
cs560fs: obj/main.o $(FS_OBJECTS) $(SHELL_OBJECTS)
	$(CC) $(LDFLAGS) $^ -o $@

test_filesystem: obj/test_filesystem.o $(FS_OBJECTS)
	$(CC) $(LDFLAGS) $^ -o $@

test_directories: obj/test_directories.o $(FS_OBJECTS)
	$(CC) $(LDFLAGS) $^ -o $@

shell: $(SHELL_OBJECTS)
	$(CC) $(LDFLAGS) $^ -o $@

#compile all .cpp to .o (two rules for whether or not the cpp has a matching .h)
obj/%o: src/%cpp
	g++ $(CFLAGS) -o $@ $<
obj/fs/%o: src/fs/%cpp src/fs/%h
	g++ $(CFLAGS) -o $@ $<
obj/fs/%o: src/fs/%cpp
	g++ $(CFLAGS) -o $@ $<
obj/shell/%o: src/shell/%cpp src/shell/%h
	g++ $(CFLAGS) -o $@ $<
obj/shell/%o: src/shell/%cpp
	g++ $(CFLAGS) -o $@ $<

clean:
	rm -f $(EXECUTABLE) $(FS_OBJECTS) $(SHELL_OBJECTS) $(MAIN_OBJECTS)
